package com.hmall.search.listener;

import com.hmall.search.constatnts.MqConstants;
import com.hmall.search.service.SearchService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 监听器
 *
 * @author zhang
 * @date 2022/06/13
 */
@Component
public class ItemListener {

    @Autowired
    @SuppressWarnings("all")
    private SearchService searchService;

    /**
     * 监听新增或修改的业务
     *
     * @param id 酒店id
     */
    @RabbitListener(queues = MqConstants.ITEM_INSERT_QUEUE)
    public void listenHotelInsertOrUpdate(Long id) {
        searchService.insertById(id);
    }

    /**
     * 监听删除的业务
     *
     * @param id 酒店id
     */
    @RabbitListener(queues = MqConstants.ITEM_DELETE_QUEUE)
    public void listenHotelDelete(Long id) {
        searchService.deleteById(id);
    }
}